﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.Secondphase
{
    public partial class Complain : BasePage
    {

        public Complain()
        {
            this.ModuleNo = Module.意见反馈.ToString();
            this.PageOperateType = OperateType.意见编辑.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();
        }
        void BindData()
        {
            if (Request.QueryString["id"] != null)
            {
                this.Controls.Add(new LiteralControl("<script>BtnDisplay()</script>"));

                this.txtEmail.Visible = false;
                this.txtTitle.Visible = false;
                this.txtMobile.Visible = false;
                this.txtName.Visible = false;
                this.FCKContent.Visible = false;
                this.txtRecivedPerson.Visible = false;

                //获得此投诉信息的详情
                int t = 0;
                HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
                System.Data.DataTable dt = new System.Data.DataTable();
                HZ.Supervise.Model.Complain complain = new HZ.Supervise.Model.Complain();
                complain.ComplainID = Request.QueryString["id"].ToString();
                complain.ReplyTime = "1900-2-2";
                complain.ComplainTime = "1900-2-2";
                complain.Status = 3;
                dt = pre.GetComplain(complain, 0, 12, out t);

                this.lblRecivedPerson.Text = dt.Rows[0]["ComplainTo"].ToString();
                this.lblRecivedPerson.Visible = true;

                this.lblContent.Text = dt.Rows[0]["Content"].ToString();
                this.lblContent.Visible = true;

                this.lblEmail.Text = dt.Rows[0]["ComplainantEmail"].ToString();
                this.lblEmail.Visible = true;

                this.lblName.Text = dt.Rows[0]["ComplainantName"].ToString();
                this.lblName.Visible = true;

                this.lblTitle.Text = dt.Rows[0]["Title"].ToString();
                this.lblTitle.Visible = true;

                this.lblMobile.Text = dt.Rows[0]["ComplainantTel"].ToString();
                this.lblMobile.Visible = true;

                this.btnComplaints.Visible = false;
                this.btnCancel.Text = "返回";
            }
        }
        /// <summary>
        /// 投诉
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnComplaints_Click(object sender, EventArgs e)
        {
            string[] complaintToIds = hfdRecivedPerson.Value.Split(',');
            string[] complaintTos = txtRecivedPerson.Text.Split(',');
            HZ.Supervise.Model.Complain Complain = new HZ.Supervise.Model.Complain();
            Complain.Title = txtTitle.Text.Trim().ToString();
            Complain.Status = 0;
            Complain.Content = FCKContent.Value.Trim().ToString();
            Complain.ComplainTime = DateTime.Now.ToShortDateString();
            Complain.ReplyTime = "1900-1-1";
            Complain.ComplainantTel = txtMobile.Text.Trim().ToString();
            Complain.ComplainantEmail = txtEmail.Text.Trim().ToString();
            Complain.ComplainantName = txtName.Text.Trim().ToString();
			Complain.UserId = CurrentAccount.GetUser().UserID;
            HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
            for (int i = 0; i < complaintTos.Length; i++)
            {
                if (complaintTos.Length == 2)
                {
                    Complain.ComplainID = Guid.NewGuid().ToString();
                    Complain.ComplainTo = complaintTos[0];
                    pre.InsertIntoComplain(Complain);
                    break;
                }
                else if (i != complaintTos.Length - 1)
                {
                    Complain.ComplainID = Guid.NewGuid().ToString();
                    Complain.ComplainTo = complaintTos[i];
                    pre.InsertIntoComplain(Complain);
                }
            }
            //HZ.Web.WebUtil.Alert("提交成功！",this);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>alert('提交成功！'); window.location.href ='ComplainList.aspx';</script>");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                Response.Redirect("../Secondphase/ComplainList.aspx");
            }
            else
            {
                this.txtEmail.Text = "";
                this.txtMobile.Text = "";
                this.txtName.Text = "";
                this.txtRecivedPerson.Text = "";
                this.txtTitle.Text = "";
                this.FCKContent.Value = "";
            }
        }
    }
}
